﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.Connection.CommandHandlers;
using PokerClient.VisualDisp;

namespace PokerClient.Commands.CommandHandlers
{
	class seatHandler : absHandler
	{
		SeatErrors serror;
		Table table;
		Client myClient;
		String message = " ";
		public seatHandler(Table table,Client myClient)
		{
			this.table = table;
			this.myClient = myClient;
		}
		public override void assignCommand(string commands)
		{
			this.commands = commands.Split(' ');
		}

		public override string work()
		{
			
			switch(this.commands[0])
			{	
				case "SEATUPTABLE-ACK":
					serror = SeatErrors.SEATUPTABLE_ACK;				
					message = "Success!";
					break;
				case "SEATDOWNTABLE-ACK":
					serror = SeatErrors.SEATDOWNTABLE_ACK;
					message = "Success!";
					break;
				default:
					serror = SeatErrors.SEAT_FAIL;
					message = this.commands[1];
					//this.myClient.sSeat = " ";
					break;
			}
			return message;
		}

		public override void analyze()
		{
			
			switch(serror)
			{
				case SeatErrors.SEATDOWNTABLE_ACK:
					table.joinGame();
					this.table.updateStatus(message);
					break;
				case SeatErrors.SEATUPTABLE_ACK:					
					this.table.updateStatus(message);
					break;
				default:
					this.table.leavSeat();
					this.table.updateStatus(message);
					break;
			}
		}
	}

	enum SeatErrors
	{
		SEATUPTABLE_ACK,
		SEATDOWNTABLE_ACK,
		SEATUPTABLE_FAIL,
		SEATDOWNTABLE_FAIL,
		SEAT_FAIL
	}
}
